'20121005
Imports System.IO
Module catchException
    Private ExceptionLog As APFile
    Private fileDate As DateTime
    Private FilePath As String
    Sub New()
        fileDate = Now
        FilePath = "ExceptionLog" + fileDate.Year.ToString + "-" + fileDate.Month.ToString("D2") + "-" + fileDate.Day.ToString("D2") + ".txt"
        ExceptionLog = New APFile(FilePath)
    End Sub
 
    Sub printExceptionInFile(ByVal Exception As Exception)


        checktime()
        'File.AppendAllText(FilePath, getNow() + " " + Exception.ToString + Environment.NewLine)
        ExceptionLog.write(getNow() + " " + Exception.ToString)


    End Sub
    Sub printExceptionInFile(ByVal exName As String, ByVal Exception As Exception)

        checktime()

        ExceptionLog.write(getNow() + " " + exName + " " + Exception.ToString)
        'File.AppendAllText(FilePath, getNow() + " " + exName + " " + Exception.ToString + Environment.NewLine)

    End Sub
    Private Function getNow() As String

        Return Now.Year.ToString + "-" + Now.Month.ToString("D2") + "-" + Now.Day.ToString("D2") + "-" + Now.Hour.ToString("D2") + ":" + Now.Minute.ToString("D2") + ":" + Now.Second.ToString("D2")
    End Function
    Private Sub WritteNow()
        checktime()
        ExceptionLog.write(getNow())
        'File.AppendAllText(FilePath, getNow() + Environment.NewLine)
    End Sub
    Sub exWritte(ByVal text As String)
        checktime()
        ExceptionLog.write(text)
        'File.AppendAllText(FilePath, text + Environment.NewLine)
    End Sub
    Sub checktime()
        If Not fileDate.Day.Equals(Now.Day) Then
            fileDate = Now
            FilePath = "ExceptionLog" + fileDate.Year.ToString + "-" + fileDate.Month.ToString("D2") + "-" + fileDate.Day.ToString("D2") + ".txt"
            ExceptionLog = New APFile(FilePath)
        End If
    End Sub
    Function getFilePath() As String
        FilePath = "ExceptionLog" + fileDate.Year.ToString + "-" + fileDate.Month.ToString("D2") + "-" + fileDate.Day.ToString("D2") + ".txt"
        Return FilePath
    End Function
End Module